import {
  HYEventStore
} from 'hy-event-store'
import {
  getRankings
} from '../service/api_music'

const rankingMap = {
  0: "newRanking",
  1: "hotRanking",
  2: "originRanking",
  3: "upRanking"
}

const rankingStore = new HYEventStore({
  state: {
    newRanking: {}, // 0: 新歌
    hotRanking: {}, // 1: 热门
    originRanking: {}, // 2: 原创
    upRanking: {} // 3: 飙升
  },
  actions: {
    getRankingDataAction(ctx) {
      // 0: 新歌榜 1: 热门榜 2: 原创榜 3: 飙升榜
      // 飙升榜
      getRankings(19723756).then(res => {
        ctx.upRanking = res.playlist
      })
      // 新歌榜
      getRankings(3779629).then(res => {
        ctx.newRanking = res.playlist
      })
      // 原创榜
      getRankings(2884035).then(res => {
        ctx.originRanking = res.playlist
      })
      // 热歌榜
      getRankings(3778678).then(res => {
        ctx.hotRanking = res.playlist
      })
    }
  }
})

export {
  rankingStore,
  rankingMap
}